package annotation.book;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/5/28
 **/
public class TestAnnotation {
    //解析解析BookStore类方法上的@Book注解信息
    public static void main(String[] args) throws NoSuchMethodException {
            //1.获取BookStore的类类型
            Class<BookStore> clazz = BookStore.class;
            //2.获得BookStore类中方法对象
            Method Purchasemethod = clazz.getDeclaredMethod("purchase");
            //3.判断当前方法上，是否有Book注解
            if(Purchasemethod.isAnnotationPresent(Book.class)){
                //4.若有Book注解，则获得方法上的注解
                Book bookAnnotation=Purchasemethod.getAnnotation(Book.class);
                //5.获得方法上注解的属性信息
                System.out.println("书名："+bookAnnotation.value());
                System.out.println("价格："+bookAnnotation.price());
                System.out.println("作者："+ Arrays.toString(bookAnnotation.author()));
            }else {
                System.out.println("purchase()方法上没有Book注解");
            }
        }
}
